Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement choice #36

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

matzipan
Copy link
Contributor

@matzipan matzipan commented Jan 2, 2024

Some things still to do:

  • Rebase
  • Fix compilation
  • Fix the choice tests
  • Check test failures
  • Extension as parent
  • Restriction as parent

Supersedes #20

@matzipan matzipan force-pushed the rebase_impl_choice branch from 4318d43 to 5495f12 Compare January 3, 2024 15:33
base: "John".to_string(),
scope: None,
}),
lastname: None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I expect more to retrieve an enum here.
The test is not easy to understand as a person has basically a first name and a last name, so it's not a choice, more a combination.

I think the example here is more relevant: https://www.w3schools.com/xml/el_choice.asp
Where. Person may have role employee or member.

So for me the expected code will be:

let model = Person::Employee("John".to_string());

// Generated part by xml-schema
enum Person {
  Employee(String),
  Member(String),
}

let model = Person {
firstname: "John".to_string(),
lastname: "".to_string(),
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case I expect to have:

Person {
  parents: vec![Parent::Firstname("John".to_string())],
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup exactly, I just patched this in one commit just to get it to compile. I am currently working on making this a vector.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry I just implemented:

  let model = Person {
    firstname_list: vec!["John".to_string()],
    lastname_list: vec![],
  };

which i notice now is a bit different from what you imagined.

Copy link
Contributor Author

@matzipan matzipan Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some attempts which try to implement this as enum, you can see the last commit here: 740c37b

Unforuntately the test fails with:

thread 'choice_multiple' panicked at xml_schema/tests/choice.rs:99:3:
assertion `left == right` failed
  left: Gift { content: [] }
 right: Gift { content: [price_history(1), price_history(3)] }

So I probably got the yaserde config wrong :(

I will pause this work for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants